<!-- 订单调整审批管理 -->
<template>
  <div class="order_adjust_approve_management">
    <Tabs v-model="curState" type="card" :animated="false" @on-click="onChangeTab">
      <TabPane label="认购调整单" name="1"></TabPane>
      <TabPane label="签约调整单" name="2"></TabPane>
    </Tabs>
    <dt-search ref="search" :xlBtn="6" @reset="resetFun"></dt-search>
    <dt-grid ref="table" page :onFetch="onFetch" />
    <process-modal ref="process" />
    <!--调整附件-->
    <adjust-enclosure ref="adjustEnclosure"></adjust-enclosure>
  </div>
</template>

<script>
  import searchOpt from './opt/search'
  import Column from './opt/columns'
  import auditMgr from '@/biz/flowApproval/processAudit.js'
  import processModal from '@/components/biz/audit/process-modal.vue'
  import adjustEnclosure from '@/views/casemanagement/salesManagement/components/adjustEnclosure.vue'
  import dt from '@dt/dt'
  export default {
    components: {
      processModal,
      adjustEnclosure
    },
    // props: ['orderType'],
    data() {
      return {
        curState: '1',
        oldState: '1',
        formValidate: {
          orgId: [],
          housesId: '',
          state: ''
        },
        filterParams: {},
        orderType: '认购'
      }
    },
    watch: {
      $route(to, from) {
        let retainParams = dt.memory.get('orderAdjustApproveManagement')

        if (to.name == 'orderAdjustApproveManagement') {
          this.formValidate.state = retainParams?.state

          this.formValidate.housesId = retainParams?.housesId
          this.formValidate.companyId = retainParams?.companyId
          this.formValidate.housesName = retainParams?.housesName

          this.$refs.search.init(this.$refs.table, new searchOpt(this).options(), this.formValidate)
          this.$refs.table.fetch()
        }
      }
    },
    methods: {
      onChangeTab(val) {
        if (val == this.oldState) return false
        this.oldState = val
        this.orderType = val == 1 ? '认购' : '签约'
        this.init()
        this.$refs.table.clearFilter()
      },
      resetFun() {
        dt.memory.remove('orderAdjustApproveManagement')
        this.formValidate = {
          orgId: [],
          housesId: '',
          state: ''
        }

        this.$refs.search.init(this.$refs.table, new searchOpt(this).options(), this.formValidate)
      },
      onFetch(data) {
        dt.memory.get('orderAdjustApproveManagement')?.UContainSelf !== undefined &&
          (data.containSelf = !dt.memory.get('orderAdjustApproveManagement'))

        this.filterParams = {
          ...data,
          auditType: this.orderType == '认购' ? 10 : 11,
          buttonType: '-1'
        }
        return auditMgr.list(this.filterParams).then((res) => {
          res &&
            res.list.forEach((item) => {
              item = Object.assign(item, item.auditData)
            })
          return res
        })
      },
      init() {
        this.$refs.table.init(this, new Column(this))
        this.$refs.table.fetch()
      },
      //查看附件
      viewAccessory(data) {
        console.log(data, '查看附件')
        data.imageAttachList = data.imageAnnexes
        data.fileAttachList = data.fileAnnexes
        data.fromPage = 'approve'
        this.$refs.adjustEnclosure.show(data)
      },
      processFun(data) {
        this.$refs.process.show({
          ...data,
          auditType: this.orderType == '认购' ? 10 : 11
        })
      },
      onDetail(data) {
        data.title = '查看'
        data.flag = 'check'
        this.$router.push({
          name: `${
            this.orderType == '认购' ? 'orderAdjust/subApproveDetail' : 'orderAdjust/contractApproveDetail'
          }`,
          query: {
            adjustmentId: data.adjustmentId,
            orderType: this.orderType,
            auditId: data.auditId,
            housesId: data.housesId,
            isflag: 'check',
            ApproveManagementFlag: true
          }
        })
      }
    },
    mounted() {
      let retainParams = dt.memory.get('orderAdjustApproveManagement')

      this.formValidate.state = retainParams?.state
      this.formValidate.housesId = retainParams?.housesId
      this.formValidate.companyId = retainParams?.companyId
      this.formValidate.housesName = retainParams?.housesName

      console.log(this.orderType, 'orderType')
      this.init()
      this.$refs.search.init(this.$refs.table, new searchOpt(this).options(), this.formValidate)
    }
  }
</script>
<style lang="scss" scoped>
  .order_adjust_approve_management {
    padding: 20px;
  }
</style>
